package com.jyx.reflect.test;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * 浅析类加载器
 * author 		jyx
 * email 		jyxsuper@163.com
 * description: MyInvocationHandler
 * Company: 	myzczk
 * datetime: 	2017年5月24日 下午6:02:01
 */
public class MyInvocationHandler implements InvocationHandler {

	private Object obj = null;
	
	public Object bind(Object object) {
		this.obj = object;
		return Proxy.newProxyInstance(object.getClass().getClassLoader(), obj.getClass().getInterfaces(), this);
	}
	
	@Override
	public Object invoke(Object proxy, Method method, Object[] args)
			throws Throwable {
		return method.invoke(this.obj, args);
	}

}

//定义项目接口
interface Subject {
  public String say(String name, int age);
}

//定义真实项目
class RealSubject implements Subject {
  @Override
  public String say(String name, int age) {
      return name + "  " + age;
  }
}
